from selenium import webdriver
from selenium.webdriver.common.by import By
import time

class BrowserOperation:
    def __init__(self):
        # 打开游览器
        self.driver = webdriver.Chrome()
        # 打开百度
        self.driver.get('https://www.baidu.com')

    def quit(self):
        time.sleep(2)
        self.driver.quit()

    def window_size(self):
        # 设置大小
        time.sleep(2)
        self.driver.set_window_size(480,800)
        # 最大化
        time.sleep(2)
        self.driver.maximize_window()
        # 最小化
        time.sleep(2)
        self.driver.minimize_window()

    def forward_back(self):
        # 后退
        time.sleep(2)
        self.driver.back()
        # 前进
        time.sleep(2)
        self.driver.forward()

    def close(self):
        # 点击新闻链接
        news = self.driver.find_element(By.LINK_TEXT,'新闻')
        news.click()
        # 关闭标签页
        time.sleep(3)
        self.driver.close()

    def refresh(self):
        # 刷新
        time.sleep(2)
        self.driver.refresh()

if __name__ == '__main__':
    b = BrowserOperation()
    # b.window_size()
    # b.refresh()
    # b.forward_back()
    # b.close()
    b.quit()